<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>钉钉风格考勤日历</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", sans-serif;
        }

        body {
            background: #f8f9fa;
            padding: 20px;
        }

        .calendar {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 6px;
            background: #fff;
            padding: 12px;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            margin-bottom: 20px;
        }

        .day {
            position: relative;
            text-align: center;
            padding: 8px 0;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .day:hover {
            background: #e6f3ff;
        }

        .day.active {
            background: #007bff;
            color: white;
            font-weight: 600;
        }

        .dot {
            position: absolute;
            bottom: 4px;
            left: 50%;
            transform: translateX(-50%);
            width: 6px;
            height: 6px;
            border-radius: 50%;
        }

        .dot.present {
            background: #4CAF50;
        }

        .dot.absent {
            background: #f44336;
        }

        .record-card {
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
            padding: 16px 20px;
            width: 340px;
            display: none;
        }

        .record-card.show {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        .record-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }

        .record-header span {
            color: #333;
            font-weight: 600;
            font-size: 16px;
        }

        .status-tag {
            background: #4CAF50;
            color: white;
            padding: 3px 8px;
            border-radius: 10px;
            font-size: 12px;
        }

        .status-tag.abnormal {
            background: #f44336;
        }

        .record-item {
            margin-top: 10px;
            font-size: 14px;
            color: #333;
        }

        .time {
            font-weight: 500;
            color: #666;
            margin-left: 6px;
        }

        .time.abnormal {
            color: #e74c3c;
            font-weight: 600;
        }

        .machine {
            color: #888;
            font-size: 13px;
            margin-left: 5px;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(5px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body>
<div class="calendar" id="calendar"></div>

<div class="record-card" id="recordCard"></div>

<script>
    // 模拟当月日期与考勤状态
    const daysInMonth = 30;
    const attendanceData = {
        29: {
            date: "2025年09月29日",
            status: "全勤",
            abnormal: false,
            records: [
                { type: "签到", time: "08:56", place: "【考勤机】武汉政通", abnormal: false },
                { type: "签退", time: "18:42", place: "【考勤机】武汉政通", abnormal: true }
            ]
        },
        18: {
            date: "2025年09月18日",
            status: "打卡异常",
            abnormal: true,
            records: [
                { type: "签到", time: "09:25", place: "【考勤机】武汉政通", abnormal: true },
                { type: "签退", time: "--", place: "", abnormal: true }
            ]
        }
    };

    const calendar = document.getElementById("calendar");
    const recordCard = document.getElementById("recordCard");

    // 渲染日历
    for (let d = 1; d <= daysInMonth; d++) {
        const dayDiv = document.createElement("div");
        dayDiv.className = "day";
        dayDiv.textContent = d;

        // 打卡标记
        const dot = document.createElement("div");
        dot.classList.add("dot");

        if (attendanceData[d]) {
            dot.classList.add(attendanceData[d].abnormal ? "absent" : "present");
        }

        dayDiv.appendChild(dot);

        // 点击显示详情
        dayDiv.addEventListener("click", () => {
            document.querySelectorAll(".day").forEach(el => el.classList.remove("active"));
            dayDiv.classList.add("active");

            if (attendanceData[d]) {
                renderRecord(recordCard, attendanceData[d]);
            } else {
                recordCard.innerHTML = `<div class="record-header"><span>2025年09月${d}日</span><div class="status-tag abnormal">未打卡</div></div>`;
                recordCard.classList.add("show");
            }
        });

        calendar.appendChild(dayDiv);
    }

    function renderRecord(card, info) {
        const header = `
        <div class="record-header">
          <span>${info.date}</span>
          <div class="status-tag ${info.abnormal ? "abnormal" : ""}">${info.status}</div>
        </div>`;
        const records = info.records
            .map(
                r => `
          <div class="record-item">
            ${r.type}
            <span class="time ${r.abnormal ? "abnormal" : ""}">
              ${r.abnormal ? "⚠️ " : ""}${r.time}
            </span>
            <span class="machine">${r.place}</span>
          </div>`
            )
            .join("");
        card.innerHTML = header + records;
        card.classList.add("show");
    }
</script>
</body>
</html>
